package com.httpclient.test;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.*;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class SimpleClient {

	public static void main(String[] args) throws ClientProtocolException,
			IOException {
		HttpClient httpclient = new DefaultHttpClient();
		HttpClient httpclientnew = new DefaultHttpClient();
		// 创建httpget.
		HttpGet httpget = new HttpGet("http://www.baidu.com/");
		System.out.println("executing request " + httpget.getURI());
		// 执行get请求.
		HttpResponse response;
		response = httpclient.execute(httpget);
		// 获取响应实体
		HttpEntity entity = response.getEntity();
		System.out.println("--------------------------------------");
		// 打印响应状态
		System.out.println(response.getStatusLine());
		if (entity != null) {
			// 打印响应内容长度
			System.out.println("Response content length: "
					+ entity.getContentLength());
			// 打印响应内容
			System.out.println("Response content: "
					+ EntityUtils.toString(entity));
		}
		System.out.println("------------------------------------");

	}

}
